<template>
  <div>
    <el-table
      ref="table"
      :data="tableData"
      border
      stripe
      :height="tableHeight"
      :header-cell-style="{'background':'#F5F4F7'}"
    >
      <el-table-column
        type="index"
        label="序号"
        width="60"
        align="center"
      />
      <el-table-column
        prop="strreceipttypename"
        label="单据类型"
      />
      <el-table-column
        prop="bytcontroltypevalue"
        label="控制方式"
      />
      <el-table-column
        prop="bytrulevalue"
        label="编号规则"
      />
      <el-table-column
        label="操作"
        width="110"
        fixed="right"
        align="center"
      >
        <template v-slot="scope">
          <el-button
            type="text"
            size="small"
            @click="detailEvent(scope.row)"
          >查看</el-button>
          <el-button
            type="text"
            size="small"
            @click="editEvent(scope.row)"
          >编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      v-if="paging.total > 0"
      background
      :current-page.sync="paging.page"
      :page-sizes="[10, 20, 30, 40]"
      :page-size.sync="paging.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="paging.total"
      @size-change="queryListByPage('search')"
      @current-change="queryListByPage"
    />
  </div>
</template>

<script>
import calculateCommonTableHeight from '@/layout/mixin/calculateCommonTableHeight'
import { queryList } from '@/api/system/bill-setting/bill-number-rules/index'
export default {
  name: 'BillNumberRulesTableArea',
  mixins: [calculateCommonTableHeight],
  data() {
    return {
      tableData: [],
      searchForm: {},
      listLoading: false,
      paging: {
        total: 0,
        page: 1,
        size: 10
      }
    }
  },
  created() {
  },
  methods: {
    // 获取列表查询
    query(searchForm) {
      this.searchForm = JSON.parse(JSON.stringify(searchForm))
      this.paging.page = 1
      this.queryListByPage()
    },
    queryListByPage(str = '') {
      if (str === 'search') {
        this.paging.page = 1
      }
      this.listLoading = true
      queryList(
        this.searchForm,
        this.paging.page,
        this.paging.size
      ).then(res => {
        if (res.code === 20000) {
          this.paging.total = res.data.total
          this.tableData = res.data.rows
        }
      }).finally(() => {
        this.listLoading = false
      })
    },
    // 查看
    detailEvent(row) {
      this.$emit('detail', row)
    },
    // 编辑
    editEvent(row) {
      this.$emit('edit', row)
    }
  }
}
</script>

<style scoped>

</style>
